// Learn cc.Class:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/class.html
//  - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/class.html
// Learn Attribute:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
//  - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
//  - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/life-cycle-callbacks.html
let base = require("panelBase");
let viewConfig = {
    btn_fh:{
        node:null,
        name:"btn_fh",
        eventType:"click",
        cb:"onBtnFhClick",
    },
    btn_shop:{
        node:null,
        name:"btn_shop",
        eventType:"click",
        cb:"onBtnShopClick"
    },

    btn_fastBuy:{
        node:null,
        name:"btn_fastBuy",
        eventType:"click",
        cb:"onBtnFastBuyClick"
    },
    btn_myGroup:{
        node:null,
        name:"btn_myGroup",
        eventType:"click",
        cb:"onBtnMyGroupClick"
    },

    gameAera:{
        node:null,
        name:"gameAera",
    },

    cakePrefab:{
        node:null,
        name:"cakePrefab",
        active:false,
    },
    btn_sell:{
        node:null,
        name:"gameAera/btn_sell",
    }
}


cc.Class({
    extends: base,

    properties: {
        logic:null,
    },

    init () {
        this._super(viewConfig)
       // cakeRoom.init();
       cc.tg.eventCenter.addEvent("updateRet",(data)=>{
                if(!this.logic || !data)
                    return ;
                this.logic.updateRet(data);
       });

       cc.tg.eventCenter.addEvent("onBuyCake",(data)=>{
                if(!this.logic || !data)
                    return ;
                this.logic.onBuyItem(data,1)
       });
       cc.tg.eventCenter.addEvent("onGainCoin",(data)=>{
            if(!this.logic || !data)
                return ;
            this.logic.onGainCoin(data); 
       })
       this.logic = this.node.getComponent("gameLogic")
       this.logic.init(viewConfig["gameAera"].node,viewConfig["cakePrefab"].node,viewConfig["btn_sell"].node)
       this.isInited = true;
      
    },

    onBtnFhClick(){
        cc.log("fh");

        cc.tg.eventCenter.dispatchEvent("showPanel",{panelName:"fh",active:true});
    },

    onBtnShopClick(){
        cc.log("shop");

        cc.tg.eventCenter.dispatchEvent("showPanel",{panelName:"shop",active:true});
    },

    onBtnFastBuyClick(){
        cc.log("fast buy");
        cc.tg.cakeRoom.buyOneItem();
    },
    onBtnMyGroupClick(){
        cc.log("my group");

        cc.tg.eventCenter.dispatchEvent("showPanel",{panelName:"myGroup",active:true});

    },

    onDestroy(){
        for(let key in viewConfig)
        {
            viewConfig[key].node = null;
        }
    },
    
});
